package com.aidong.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class MyPersonalInfoUtil {
	
	private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 };  
	private final static String[] constellationArr = new String[] { "摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座" };  
	  
	/**
	 * 根据日期计算星座
	 * @param month 月
	 * @param day 日
	 * @return 星座
	 */
	public static String getConstellation(int month, int day) {  
	    return day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month];  
	}

	/**
	 * 根据星座计算日期段
	 * @param constellation 星座
	 * @return 日期[MM-dd,MM-dd]
	 */
	public static String[] getConstellationDay(String constellation) {
		int n = 0;
		for(int i=1; i<constellationArr.length; i++) {
			if(constellationArr[i].equals(constellation)) {
				n = i;
				break;
			}
		}
		String dt[] = new String[2];
		if(n>0) {
			dt[0] = (n<10?"0":"")+n + "-" + dayArr[n-1];
			if(n==12)
				dt[1] = "01-" + (dayArr[0]-1);
			else
				dt[1] = (n<9?"0":"")+(n+1) + "-" + (dayArr[n]-1);
		}
		return dt;
	}
	
	/**
	 * 根据生日计算年龄
	 * @param birthday 出生日期
	 * @return
	 * @throws Exception 
	 */
	public static int getAgeByBirthday(String birth) throws Exception {
		Calendar cal = Calendar.getInstance();

		SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
		Date birthday = sim.parse(birth);
		
		if (cal.before(birthday)) {
			throw new IllegalArgumentException(
					"The birthDay is before Now.It's unbelievable!");
		}

		int yearNow = cal.get(Calendar.YEAR);
		int monthNow = cal.get(Calendar.MONTH) + 1;
		int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);

		cal.setTime(birthday);
		int yearBirth = cal.get(Calendar.YEAR);
		int monthBirth = cal.get(Calendar.MONTH) + 1;
		int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);

		int age = yearNow - yearBirth;

		if (monthNow <= monthBirth) {
			if (monthNow == monthBirth) {
				if (dayOfMonthNow < dayOfMonthBirth) {
					age--;
				}
			} else {
				age--;
			}
		}
		return age;
	}
	
	/**
	 * 魅力部位
	 * 数据字段转换
	 * @param partId
	 * @return
	 */
	public static String charmPart(String partId){
		
		String arrName = "";
		if(!"".equals(partId) && partId != null){
			String[] arrId = partId.split(",");
			if(arrId.length > 0){
				for (int i = 0; i < arrId.length; i++) {
					if("0".equals(arrId[i])){
						arrName += "脸部   ";
					}
					if("1".equals(arrId[i])){
						arrName += "颈部   ";
					}
					if("2".equals(arrId[i])){
						arrName += "胸部   ";
					}
					if("3".equals(arrId[i])){
						arrName += "臂部   ";
					}
					if("4".equals(arrId[i])){
						arrName += "腰部   ";
					}
					if("5".equals(arrId[i])){
						arrName += "臀部   ";
					}
					if("6".equals(arrId[i])){
						arrName += "腿部   ";
					}
					if("7".equals(arrId[i])){
						arrName += "脚步   ";
					}
				}
			}
		}
		
		return arrName;
	}
	
	/**
	 * 上下午转换
	 * @return
	 */
	public static String dateConversion(int pm){
		String msg = "";
		if(pm == 1){
			msg = "上午";
		}else if(pm == 2){
			msg = "下午";
		}
		return msg;
	}
}
